﻿<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        HitCountDAL hitcountDAL = new HitCountDAL();
        //lay trong database ra gan vao bien
        int SiteCounter = (int)hitcountDAL.GetHitCounter().Rows[0]["hitcount"];
        int CounterOnline = 0;
        
        //dem so nguoi truy cap website
        Application["Hitcounter"] = SiteCounter;
        
        //dem so nguoi dang online
        Application["CounterOnline"] = CounterOnline;
       
    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown
    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
        //tang so nguoi truy cap len 1
        Application["HitCounter"] = (int)Application["HitCounter"] + 1;
        //tang so nguoi online len 1
        Application["CounterOnline"] = (int)Application["CounterOnline"] + 1;
    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
        Application["CounterOnline"] = (int)Application["CounterOnline"] - 1;
        
        HitCountDAL hitcountDAL = new HitCountDAL();
        hitcountDAL.UpdateHitCounter((int)Application["HitCounter"]);
    }
       
</script>
